package com.keshe.service;

import com.keshe.dao.RoomDao;
import com.keshe.domain.Room;

import java.util.List;

public class RoomContorller {

    //显示房间信息至table
    public String[][] showALL() {
        RoomDao rd = new RoomDao();
        List<Room> allRoom = rd.select();
        String table[][] = new String[allRoom.size()][9];
        for (int i = 0; i < allRoom.size(); i++) {
            table[i][0] = allRoom.get(i).getRoomid();
            table[i][1] = allRoom.get(i).getHousename();
            table[i][2] = allRoom.get(i).getHomeloc();
            table[i][3] = Integer.toString(allRoom.get(i).getHousecoast());
            table[i][4] = allRoom.get(i).getHousesize();
            table[i][5] = allRoom.get(i).getHousesnull();
            table[i][6] = allRoom.get(i).getHousesclean();
            table[i][7] = allRoom.get(i).getHousesdesc();
            table[i][8] = null;
        }
        return table;
    }

    //添加客房信息
    public int addRoom(String roomid, String housename, String homeloc, int housecoast, String housesize,String housesnull, String housesclean, String housesdesc) {
        String coast = Integer.toString(housecoast);
        int count = 0;
        if (roomid.equals("") || housename.equals("") || homeloc.equals("") || coast.equals("") || housesnull.equals("") || housesclean.equals("") || housesdesc.equals("")) {
            count = -1;
        }
        Room rm = new Room(roomid, housename, homeloc, housecoast,housesize, housesnull, housesclean, housesdesc);
        RoomDao rc = new RoomDao();
        count = rc.insert(rm);//调用数据库
        return count;
    }

    //查询客房信息(根据房间类型)
    public String[][] selectName(String name) {
        RoomDao rd = new RoomDao();
        List<Room> allRoom = rd.selectName(name);
        String table[][] = new String[allRoom.size()][9];
        for (int i = 0; i < allRoom.size(); i++) {
            table[i][0] = allRoom.get(i).getRoomid();
            table[i][1] = allRoom.get(i).getHousename();
            table[i][2] = allRoom.get(i).getHomeloc();
            table[i][3] = Integer.toString(allRoom.get(i).getHousecoast());
            table[i][4] = allRoom.get(i).getHousesize();
            table[i][5] = allRoom.get(i).getHousesnull();
            table[i][6] = allRoom.get(i).getHousesclean();
            table[i][7] = allRoom.get(i).getHousesdesc();
            table[i][8] = null;
        }
        System.out.println("房间类型查询成功！");
        return table;
    }

    //查询客房信息(根据编号类型)
    public String[][] selectId(String id) {
        RoomDao rd = new RoomDao();
        List<Room> allRoom = rd.selectId(id);
        String table[][] = new String[allRoom.size()][9];
        for (int i = 0; i < allRoom.size(); i++) {
            table[i][0] = allRoom.get(i).getRoomid();
            table[i][1] = allRoom.get(i).getHousename();
            table[i][2] = allRoom.get(i).getHomeloc();
            table[i][3] = Integer.toString(allRoom.get(i).getHousecoast());
            table[i][4] = allRoom.get(i).getHousesize();
            table[i][5] = allRoom.get(i).getHousesnull();
            table[i][6] = allRoom.get(i).getHousesclean();
            table[i][7] = allRoom.get(i).getHousesdesc();
            table[i][8] = null;
        }
        System.out.println("编号查询成功！");
        return table;
    }

    //修改客房信息
    public int updateRoom(String id, String housename, String homeloc, int housecoast, String housesize,String housesnull, String housesclean, String housesdesc) {

        RoomDao rd = new RoomDao();
        String coast = Integer.toString(housecoast);
        int count = 0;
        if (id.equals("") || housename.equals("") || homeloc.equals("") || coast.equals("")||housesize.equals("") || housesnull.equals("") || housesclean.equals("") || housesdesc.equals("")) {
            count = -1;
            return count;
        }
        count = rd.update(id, housename, homeloc, housecoast, housesize,housesnull, housesclean, housesdesc);
        return count;
    }
    //删除客房
    public int deleteRoom(String id){
        RoomDao rd=new RoomDao();
        int count=0;
        if(id.equals("")){
            count=-1;
            return count;
        }
        count=rd.delete(id);
        return count;
    }
}
